<template>
  <div class="ke">
    <!-- <div class="powertop">
      <router-link class="powertopli " to="/yongjinzhichu/zhichuguanli" v-if="checkquanxian('V0201').length > 0">支出订单管理</router-link>
      <router-link class="powertopli " to="/yongjinzhichu/yongjinzhichu" v-if="checkquanxian('V0202').length > 0">佣金支出</router-link>
      <router-link class="powertopli " to="/yongjinzhichu/zhichudakuanshenhe" v-if="peizhi.second_commission_examine && checkquanxian('V0204').length > 0">支出审核</router-link>
      <router-link class="powertopli " to="/yongjinzhichu/zhichudakuan" v-if="checkquanxian('V0203').length > 0">支出打款</router-link>

      <router-link class="powertopli" to="/yongjinzhichu/zhichupeizhi"  v-if="zhichupeizhi">支出配置</router-link>
      <router-link class="powertopli powertopact" to="/yongjinzhichu/yongjinzhichubaobiao" v-if="checkquanxian('V0205').length > 0">佣金支出报表</router-link>
    </div> -->
    <top2></top2>
    <div v-loading='loading' style="padding: 20px;">
      <div class="kflexc" style="margin-bottom: 20px;">

        <div class="lia" :class="act == 1?'acts':''" @click="search(1)">分销商报表</div>
        <div class="lia" :class="act == 2?'acts':''" @click="search(2)">月支出报表</div>
      </div>

      <div class="kflexc">
        <div style="width: 220px; margin-right: 20px; margin-bottom: 20px;" v-if="act == 1">
          <el-date-picker  v-model="all.date"  type="month" value-format="yyyy-MM" placeholder="选择月"></el-date-picker>
        </div>
        <div style="width: 220px; margin-right: 20px; margin-bottom: 20px;"  v-if="act == 2">
          <el-select clearable v-model="all.merchant_name"  style="width: 220px;" filterable placeholder="选择分销商">
            <el-option :label="item.name" :value="item.name"  v-for="item in fenxiaoshanglists" :key="item.child_shop_id" ></el-option>
          </el-select>
        </div>
        <div style="width: 220px; margin-right: 20px; margin-bottom: 20px;">

          <el-select  v-model="all.cm_id" style="width: 220px;" placeholder="选择客户经理" filterable clearable>
            <el-option :label="item.name" :value="item.id"  v-for="item in kehujinglilists" :key="item.id" ></el-option>
          </el-select>
        </div>

        <el-button type="danger" round  style="margin-right: 20px; margin-bottom: 20px;" @click="search()">搜索</el-button>

      </div>

      <el-table :data="list" border style="width: 100%; margin: 20px 0;" ref="multipleTable" >

        <el-table-column align='center' key="merchant_name" prop='merchant_name' label="分销商" v-if="act == 1"></el-table-column>

        <el-table-column align='center' key="date" prop='date' label="月份" v-if="act == 2"></el-table-column>
        <el-table-column align='center' prop='fazhan_order_count' label="发展订单数"></el-table-column>
        <el-table-column align='center' prop='jiesuan_order_count' label="结算订单数"></el-table-column>
        <el-table-column align='center' prop='jiesuan_amount' label="结算金额"></el-table-column>
        <el-table-column align='center' prop='tixian_amount' label="提现金额"></el-table-column>
        <el-table-column align='center' label="操作">
          <template slot-scope="scope">
            <!-- <el-button type="text" @click="mingxi(scope.row)">查看分销商明细</el-button> -->
          </template>
        </el-table-column>
      </el-table>
      <el-pagination style="text-align: right;" background layout="total,prev, pager, next" :current-page="all.page" @current-change="fanye" :page-size="all.page_size" :total="total"></el-pagination>
    </div>
  </div>
</template>

<script>
  import top2 from './top.vue'
  import axios from 'axios'
  import top from '@/components/top.vue'
  import left from '@/components/left.vue'
  import foot from '@/components/foot.vue'
  import moment from "moment";
  import XLSX from 'xlsx';
  import {
      read,utils
    } from 'xlsx'

  export default {
    components: {
      "left": left,
      "top": top,
      "foot": foot,
      top2
    },
    name: "ke",
    data() {
      return {
        loading:false,
        list:"",
        all:{
          page:1,
          page_size:20,
          date:"",
          cm_id:"",
          merchant_name:""
        },
        total:0,
        kehujinglilists:[],
        fenxiaoshanglists:[],
        act:1,
        peizhi:"",
        zhichupeizhi:false
      }
    },
    created() {
      this.getlist()

      if(JSON.parse(localStorage.getItem('USER')).id == JSON.parse(localStorage.getItem('SHOP')).shop_id){
        this.zhichupeizhi = true
      }


      //获取客户经理
      axios.get('/api/plan-market/user/userManagerList')
        .then(response => {
          if (response.data.msg.code == 0) {
             this.kehujinglilists = response.data.data
          } else {
             this.$message.error(response.data.msg.info);
          }
      })
      //获取全部分销商
      axios.get('/api/gth/partner/list?page_size=2000')
        .then(response => {
          if (response.data.msg.code == 0) {
            this.fenxiaoshanglists = response.data.data.data
          } else {
            this.$message.error(response.data.msg.info);
          }
        })
      // axios.get('/api/plan-market/expend/shopConfigInfo')
      //   .then(response => {
      //     if (response.data.msg.code == 0) {
      //       this.peizhi = response.data.data

      //     } else {
      //       this.$message.error(response.data.msg.info);
      //     }
      // })

    },
    mounted() {

    },
    methods: {
      search: function(val) {
        if(val){
          this.act = val
        }

        this.all.page = 1
        this.getlist()
      },
      //翻页
      fanye: function(page) {
        this.loading = true
        this.all.page = page
        this.getlist()
      },
      //获取列表
      getlist: function() {
        if(this.act == 2){

          axios.get('/api/plan-market/expend/form',{params:this.all})
            .then(response => {
              if (response.data.msg.code == 0) {
                this.list = response.data.data
                // this.total = response.data.data.total
                this.loading = false
              } else {
                this.$message.error(response.data.msg.info);
              }
            })
        }
        if(this.act == 1){
          if(this.all.date == ''){
            this.all.date = moment().format('yyyy-MM')
          }

          axios.get('/api/plan-market/expend/merchant/form',{params:this.all})
            .then(response => {
              if (response.data.msg.code == 0) {
                this.list = response.data.data
                // this.total = response.data.data.total
                this.loading = false
              } else {
                this.$message.error(response.data.msg.info);
              }
            })
        }

      }
    }
  }
</script>

<style lang="scss" scoped>
  .ke {

    .lia{ padding: 8px 20px; margin: 0 15px 0 0; border-radius: 10px; cursor: pointer; background: rgb(239, 239, 239); color: #555; font-size: 14px;}
    .acts{ background: #2974FF !important; color: #fff !important;}

    /deep/ .el-radio{ display: flex; align-items: center;}
    .powertop {
    	display: flex;
    	background:#f9f9f9;
    }
    .powertopli {
    	flex-basis: 180px;
    	line-height: 50px;
    	border-bottom: 3px #F9F9F9 solid;
    	color: #727272;
    	border-right: 1px #F9F9F9 solid;
    	font-size: 16px;
    	text-align: center;
    }
    .router-link-active {
    	background: #FFFFFF;
    	border-bottom: 3px #2974FF solid;
    }
    /deep/ .el-pagination.is-background .btn-prev:disabled{ background: rgba(246, 246, 246, 0.3); border: 1px rgba(167, 167, 167, 0.3) solid;}
    /deep/ .el-pagination.is-background .btn-next:disabled{ background: rgba(246, 246, 246, 0.3); border: 1px rgba(167, 167, 167, 0.3) solid;}
    /deep/ .el-pagination.is-background .btn-next{ background: rgba(246, 246, 246,1); border: 1px rgba(167, 167, 167,1) solid;}
    /deep/ .el-pagination.is-background .btn-prev{ background: rgba(246, 246, 246,1); border: 1px rgba(167, 167, 167,1) solid;}
    /deep/ .el-pagination.is-background .el-pager li:not(.disabled).active{ background-color: #2974FF;}
    /deep/ .el-pagination.is-background .el-pager li:not(.disabled).active:hover {
        color: #fff;
    }
    /deep/ .el-pagination.is-background .el-pager li:not(.disabled):hover {
        color: #2974FF;
    }
    /deep/ .el-pager li{ border-radius: 14px; background: rgba(255, 255, 255, 1); border: 1px rgba(167, 167, 167, 0.3) solid;}
    /deep/ .btn-prev{ border-radius: 14px; padding: 0 10px;}
    /deep/ .btn-next{ border-radius: 14px; padding: 0 10px;}

    /deep/ .el-table th{ background: rgb(246, 246, 246);}
    /deep/ .el-input__inner{ line-height: 36px; height: 36px; font-size: 12px; background: rgb(247, 248, 250);  border: 0;}
    /deep/ .el-date-editor .el-range-input{ background: rgb(247, 248, 250); }
    /deep/ .el-button{ padding: 11px 23px !important;}
    /deep/ .el-button--mini{ padding: 6px 15px !important;}
    /deep/ .el-button--danger {
        color: #FFF;
        background-color: #2974FF;
        border-color: #2974FF;
    }
    .team {
    	background: #F9F9F9;
    }
    /deep/ .baise .el-input__inner{ line-height: 36px; height: 36px; font-size: 12px; background: rgb(255,255,255);  border: 0;}
  }
</style>
